#include "vector.h"
#include <iostream> // why is this here? for debugging
#include <cmath>

/**********************************************************
 * Operator =
 **********************************************************/
Vector &Vector::operator = (const Vector &rhs)
{
   if (this == &rhs) return *this; // handle self assignment
   //assignment operator

   this->x = rhs.x;
   this->y = rhs.y;
   m_dx    = rhs.m_dx;
   m_dy    = rhs.m_dy;


   return *this;
}

/**********************************************************
 * Operator +=
 **********************************************************/
Vector &Vector::operator += (const Vector &rhs)
{
   m_dx += -sin(deg2rad(m_angle)) / 4;
   m_dy +=  cos(deg2rad(m_angle)) / 4;

   return *this;
}

/**********************************************************
 * Operator ++
 **********************************************************/
void Vector::operator ++ (int postfix)
{
   wrap();
   addX(m_dx);
   addY(m_dy);
}

/**********************************************************
 * Returns the point
 **********************************************************/
Point Vector::getPoint()
{
   Point p;
   p.setX(x);
   p.setY(y);
   return p;
}

/**********************************************************
 * Wrap :
 * Checks to see if the point went off the screen.
 * If so, the point will go to the opposite side of the
 * screen.
 **********************************************************/
void Vector::wrap()
{
   if (x > getXMax())
      x = x - (getXMax() * 2);
   else if(x < getXMin())
      x = x + (getXMax() * 2);
   else if (y > getYMax())
      y = y - (getYMax() * 2);
   else if (y < getYMin())
      y = y + (getYMax() * 2);
}

/**********************************************************
* setPoint
 **********************************************************/
void Vector::setPoint(const Point &p)
{
   setX(p.getX());
   setY(p.getY());
}


